<?
include("./_common.php");
include("$g4[path]/_head.php");

$shop = get_shop();

if(!$startDate || $startDate == ""){$startDate = date("Ymd");}
if(!$endDate || $endDate == ""){$endDate = date("Ymd");}

$tmp_startDate = substr($startDate,0,4)."-".substr($startDate,4,2)."-".substr($startDate,6,2);
$tmp_endDate = substr($endDate,0,4)."-".substr($endDate,4,2)."-".substr($endDate,6,2);

$beTween = " and (buy_datetime >= '".$tmp_startDate." 00:00:00' and buy_datetime <= '".$tmp_endDate." 23:59:59') ";

if($status)
{
	$status_search = " and status = '".substr($status,1,1)."' ";
}

if ($stx)
{
    $sql_search = " and ( ";
    $sql_search .= " concat(o_name,s_name,mb_id,o_subject) like '%$stx%' ";
    $sql_search .= " )";
}



$sql = "select * from g4_order where mb_id='".$member[mb_id]."' $beTween $sql_search $status_search";

if (!$sst) {
    $sst  = "idx";
    $sod = "desc";
}
$sql.= " order by $sst $sod ";

$total_count = mysql_num_rows(mysql_query($sql));

$rows = 10;
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

$sql.=" limit $from_record, $rows";
$rst = mysql_query($sql);

$RowNum = $total_count - $from_record;

$row_count = mysql_num_rows(mysql_query($sql));
$pagelist = get_paging("5", $page, $total_page, "$_SERVER[PHP_SELF]?status=$status&startDate=$startDate&endDate=$endDate$qstr&page=");

$colspan = "8";
?>
<style>
.btn1{height:20px;border:solid 1px #D7D7D7;background:#EFEFEF;color:#000000;width:40px;cursor:pointer}
</style>
<link rel="stylesheet" href="<?=$g4['path']?>/shop/style.css" type="text/css">
<script language="javascript" src="<?=$g4['path']?>/shop/shop.js"></script>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td align="center">

			<table cellpadding="0" cellspacing="1" border="0" width="100%">
				<colgroup>
					<col width="50">
					<col width="">
					<col width="100">
					<col width="120">
					<col width="80">
					<col width="80">
					<col width="100">
					<col width="40">
				</colgroup>
				<tr>
					<form name=fsearch method=get>
					<td colspan="<?=$colspan?>" align="right">
					검색기간 : 
					<input type="text" class="ed" style="width:65px" name="startDate" readonly value="<?=$startDate?>" id="mb_start" onclick="win_calendar('mb_start', document.getElementById('mb_start').value, '');">
					~
					<input type="text" class="ed" style="width:65px" name="endDate" readonly value="<?=$endDate?>" id="mb_end" onclick="win_calendar('mb_end', document.getElementById('mb_end').value, '');">
					상태 : 
					<select name="status">
						<option value="">전체</option>
						<?
						for($i=0;$i<=8;$i++)
						{
						?>
						<option value="<?="S".$i?>" <?if("S".$i == $status){echo("selected");}?>><?=get_status($i);?></option>
						<?}?>
					</select>
					검색 : 
					<input type="text" name="stx" class="ed" style="width:100px" value="<?=$stx?>">
					<button class="btn1" style="cursor:pointer;height:20px;width:45px" onclick="submit();">검색</button>
					</td>
					</form>
				</tr>
				<tr height="25" bgcolor="EFEFEF" align="center">
					<td>순번</td>
					<td><?=subject_sort_link("o_subject","status=$status&startDate=$startDate&endDate=$endDate")?>상품명</a></td>
					<td><?=subject_sort_link("o_name","status=$status&startDate=$startDate&endDate=$endDate")?>주문자명</a></td>
					<td><?=subject_sort_link("pay_amount","status=$status&startDate=$startDate&endDate=$endDate")?>결제금액</a></td>
					<td><?=subject_sort_link("pay_method","status=$status&startDate=$startDate&endDate=$endDate")?>결제방법</a></td>
					<td><?=subject_sort_link("status","status=$status&startDate=$startDate&endDate=$endDate")?>상태</a></td>
					<td><?=subject_sort_link("buy_datetime","status=$status&startDate=$startDate&endDate=$endDate")?>주문일시</a></td>
					<td></td>
				</tr>
				<form name="sAll" method="post" action="order_list_update.php">
				<input type="hidden" name="Mode" value="STATUS">
				<?
				while($row = mysql_fetch_array($rst))
				{
				?>
				<tr height="50" align="center" onmouseover="this.style.background='#CCFFFF'" onmouseout="this.style.background='#FFFFFF'">
					<td><?=number_format($RowNum,0)?></td>
					<td align="left"><?=cut_str($row[o_subject],60)?></td>
					<td><?=$row[o_name]?></td>
					<td align="right">
						<table cellpadding="0" cellspacing="0" border="0" width="100%">
							<tr bgcolor="FFCCCC">
								<td>상품총액</td>
								<td align="right"><?=number_format($row[pay_price])?>원</td>
							</tr>
							<tr bgcolor="FFFFCC">
								<td>배송비</td>
								<td align="right"><?=number_format($row[pay_tranc])?>원</td>
							</tr>
							<tr bgcolor="CCFFCC">
								<td>포인트결제</td>
								<td align="right"><?=number_format($row[pay_point])?>원</td>
							</tr>
							<tr bgcolor="CCCCFF">
								<td>결제총액</td>
								<td align="right"><?=number_format($row[pay_amount])?>원</td>
							</tr>
						</table>
					</td>
					<td><?=get_paymethod($row[pay_method])?></td>
					<td onmouseover="document.all('<?=$row[oid]?>').style.display='inline';"  onmouseout="document.all('<?=$row[oid]?>').style.display='none';">
					<?=get_status($row[status])?>
					<DIV style="position:absolute;display:none;" id="<?=$row[oid]?>">
					<table cellpadding="5" cellspacing="1" border="0" width="250" bgcolor="#CCCCCC" style="position:absolute;left:-150px;top:+20px">
					<?
					$tmp_status_history = explode("/",$row[status_history]);
					for($i=0;$i<count($tmp_status_history);$i++)
					{
						$tmp_history = explode("|",$tmp_status_history[$i]);
						?>
						<tr bgcolor="#FFFFFF">
							<td><?=number_format($i+1)?></td>
							<td><?=get_status($tmp_history[0]);?></td>
							<td><?=$tmp_history[1]?></td>
						</tr>
						<?
					}
					?>
					</table>
					</DIV>
					</td>
					<td><?=str_replace(" ","<br>",$row[buy_datetime])?></td>
					<td>
					<img src='<?=$g4[admin_path]?>/img/icon_view.gif' border=0 title='보기' style="cursor:pointer" onclick="location.href='./order.php?OID=<?=$row[oid]?>';">
					</td>
				</tr>
				<tr><td colspan="<?=$colspan?>" height="1" bgcolor="#d7d7d7"></td></tr>
				<?
					$RowNum--;
				}
				?>
				<tr><td colspan="<?=$colspan?>" height="40" align="right"><?=$pagelist?></td></tr>
				</form>
			</table>

		</td>
	</tr>
</table>
<?
include("$g4[path]/_tail.php");

?>